﻿'/* Copyright (c) 2009, Graeme Grant (graeme@live.com.au)
' * All rights reserved.
' *
' * Redistribution and use in source and binary forms, with or without
' * modification, are permitted provided that the following conditions are met:
' *
' *   * Redistributions of source code must retain the above copyright
' *     notice, this list of conditions and the following disclaimer.
' * 
' *   * Redistributions in binary form must reproduce the above copyright
' *     notice, this list of conditions and the following disclaimer in the
' *     documentation and/or other materials provided with the distribution.
' * 
' *   * The name Graeme Grant may not be used to endorse or promote products
' *     derived from this software without specific prior written permission.
' *
' * THIS SOFTWARE IS PROVIDED BY GRAEME GRANT ``AS IS'' AND ANY
' * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
' * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
' * DISCLAIMED. IN NO EVENT SHALL Dr. WPF BE LIABLE FOR ANY
' * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
' * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
' * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
' * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
' * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
' * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
' */

Imports System.Xml.Serialization
Imports System.IO
Imports System.Drawing

<Serializable()> _
Public Class ColorHSV

    Public Sub New(ByVal Hue As Integer, ByVal Saturation As Integer, ByVal Value As Integer)
        _Hue = Hue
        _saturation = Saturation
        _value = Value
    End Sub

    Public Sub New(ByVal EtsyHSV As String)
        Dim x() As String = Split(EtsyHSV, ";")
        If x.Length = 3 Then
            _Hue = x(0)
            _saturation = x(1)
            _value = x(2)
        End If
    End Sub

    Public Overrides Function ToString() As String
        Return String.Format("{0};{1};{2}", _Hue, _saturation, _value)
    End Function

    <XmlElement("hue")> _
    Private _Hue As Integer
    Public Property Hue() As Integer
        Get
            Return _Hue
        End Get
        Set(ByVal value As Integer)
            _Hue = value
        End Set
    End Property

    <XmlElement("saturation")> _
    Private _saturation As Integer
    Public Property Saturation() As Integer
        Get
            Return _saturation
        End Get
        Set(ByVal value As Integer)
            _saturation = value
        End Set
    End Property

    <XmlElement("value")> _
    Private _value As Integer
    Public Property Value() As Integer
        Get
            Return _value
        End Get
        Set(ByVal value As Integer)
            _value = value
        End Set
    End Property

End Class

<Serializable()> _
Public Class ColorRGB

    <XmlElement("color")> _
    Private _Color As Color
    Public Property Color() As Color
        Get
            Return _Color
        End Get
        Set(ByVal value As Color)
            _Color = value
        End Set
    End Property

    Public Sub New(ByVal Red As Byte, ByVal green As Byte, ByVal blue As Byte)
        _Color = Color.FromArgb(CInt(Red), CInt(green), CInt(blue))
    End Sub

    Public Sub New(ByVal Red As Integer, ByVal green As Integer, ByVal blue As Integer)
        _Color = Color.FromArgb(Red, green, blue)
    End Sub

    Public Sub New(ByVal color As System.Drawing.Color)
        _Color = color
    End Sub

    Public Sub New(ByVal EtsyColor As String)
        If Not EtsyColor = Nothing Then
            _Color = Color.FromArgb(CInt(String.Format("&h{0}", EtsyColor.Substring(1, 2))), _
                                    CInt(String.Format("&h{0}", EtsyColor.Substring(3, 2))), _
                                    CInt(String.Format("&h{0}", EtsyColor.Substring(5, 2))))
        End If
    End Sub

    Public Overrides Function ToString() As String
        Return String.Format("#{0:X2}{1:X2}{2:X2}", _Color.R, _Color.G, _Color.B)
    End Function

End Class
